<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>sock: E:/git/sock/sock/net/tcp_acceptor.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">sock
   &#160;<span id="projectnumber">v0.11</span>
   </div>
   <div id="projectbrief">C++ Network Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_885cc87fac2d91e269af0a5a959fa5f6.html">E:</a></li><li class="navelem"><a class="el" href="dir_4e091ed8704426a7a4980368ba259fde.html">git</a></li><li class="navelem"><a class="el" href="dir_99ede9081e3122cb31ab1bd7b142cd6c.html">sock</a></li><li class="navelem"><a class="el" href="dir_7c33e989e8c050d7b2ba91a16c41033d.html">sock</a></li><li class="navelem"><a class="el" href="dir_d903d5916af6fe48bd2085e947d1c878.html">net</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">tcp_acceptor.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="tcp__acceptor_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Name         : tcp_acceptor.h</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * Author       : 671643387</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Date         : 2015年10月6日</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * Description  :</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *****************************************************************************/</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef SOCK_NET_TCP_ACCEPTOR_H_</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define SOCK_NET_TCP_ACCEPTOR_H_</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="net__event__handler_8h.html">sock/net/net_event_handler.h</a>&gt;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="socket_8h.html">sock/net/socket.h</a>&gt;</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="tcp__connection_8h.html">sock/net/tcp_connection.h</a>&gt;</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacesock.html">sock</a></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;{</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    <span class="keyword">namespace </span>net</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    {</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;        <span class="keyword">class </span>TcpServer;</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;</div>
<div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="classsock_1_1net_1_1_tcp_acceptor.html">   24</a></span>&#160;        <span class="keyword">class </span><a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html">TcpAcceptor</a> : <span class="keyword">public</span> <a class="code" href="classsock_1_1net_1_1_net_event_handler.html">NetEventHandler</a></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;        {</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00027"></a><span class="lineno"><a class="line" href="classsock_1_1net_1_1_tcp_acceptor.html#ae9d6183dfcfdc39fee3d3cd861fd7ad2">   27</a></span>&#160;            <span class="keyword">typedef</span> boost::function&lt;TcpConnectionPtr&amp;(sock_t)&gt; <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#ae9d6183dfcfdc39fee3d3cd861fd7ad2">TcpConnectonGetFunc</a>;</div>
<div class="line"><a name="l00028"></a><span class="lineno"><a class="line" href="classsock_1_1net_1_1_tcp_acceptor.html#a4f61b7c7e32c3cc975f394efbfced020">   28</a></span>&#160;            <span class="keyword">typedef</span> boost::function&lt;void(TcpConnectionPtr&amp;)&gt; <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#a4f61b7c7e32c3cc975f394efbfced020">PassTcpConnectionPtrRefFunc</a>;</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;            <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#a459593c127612503a4c6c21a677a43f5">TcpAcceptor</a>(<span class="keywordtype">void</span>);</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;            <span class="keyword">virtual</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#affefddc37347a117e5a51dfe86cd781f">~TcpAcceptor</a>(<span class="keywordtype">void</span>);</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;            <span class="keywordtype">bool</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#a3f7e8ab49db7fa4b333430d0cf0f13ce">open</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* addr, <span class="keywordtype">int</span> port, <span class="keywordtype">int</span> backlog);</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;            <span class="keywordtype">void</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#a1e55a3bc5b17b5960419afe981c4b3f7">close</a>(<span class="keywordtype">void</span>);</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#ad93eec19093d98d84aaa7f74486373f7">handleInput</a>(<span class="keywordtype">void</span>);     <span class="comment">/* @override */</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#a8c313189b9166036e374750ddc64ea97">handleOutput</a>(<span class="keywordtype">void</span>);     <span class="comment">/* @override */</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#aaff5bd626bb6e5a1ce1c972fb6faf593">handleError</a>(<span class="keywordtype">void</span>);     <span class="comment">/* @override */</span></div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#aef1361f3392c7757cc0fc0a13b15163d">handleClose</a>(<span class="keywordtype">void</span>);     <span class="comment">/* @override */</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classsock_1_1net_1_1_tcp_acceptor.html#afd658b58966444f446dd9b1cf747a04c">handleHeartbeat</a>(<span class="keywordtype">void</span>); <span class="comment">/* @override */</span></div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;        <span class="keyword">private</span>:</div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="classsock_1_1net_1_1_tcp_acceptor.html#a3ecf3132e8c4bf890c07853cfab7619c">   57</a></span>&#160;            <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classsock_1_1net_1_1_tcp_server.html">TcpServer</a>;</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;            sock_t getSock(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> sock_; }</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;            <span class="keywordtype">void</span> setConnectionCreator(TcpConnectonGetFunc creator) { connCreatorFn_ = creator; }</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;            <span class="keywordtype">void</span> setConnectionEstablishedFN(PassTcpConnectionPtrRefFunc fn) { connectionEstablishedFn_ = fn; }</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;        <span class="keyword">private</span>:</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;            sock_t sock_;                       <span class="comment">/* 本地套接字 */</span></div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;            <span class="keyword">struct </span>sockaddr_in addr_;           <span class="comment">/* 监听地址 */</span></div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            TcpConnectonGetFunc connCreatorFn_;                     <span class="comment">/* 连接创建函数 */</span></div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            PassTcpConnectionPtrRefFunc connectionEstablishedFn_;   <span class="comment">/* 连接接收回调 */</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        };</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    }</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;}</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* SOCK_NET_TCP_ACCEPTOR_H_ */</span><span class="preprocessor"></span></div>
<div class="ttc" id="classsock_1_1net_1_1_net_event_handler_html"><div class="ttname"><a href="classsock_1_1net_1_1_net_event_handler.html">sock::net::NetEventHandler</a></div><div class="ttdoc">网络事件处理器 </div><div class="ttdef"><b>Definition:</b> net_event_handler.h:20</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_a1e55a3bc5b17b5960419afe981c4b3f7"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#a1e55a3bc5b17b5960419afe981c4b3f7">sock::net::TcpAcceptor::close</a></div><div class="ttdeci">void close(void)</div><div class="ttdoc">关闭接收器 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:66</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_a459593c127612503a4c6c21a677a43f5"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#a459593c127612503a4c6c21a677a43f5">sock::net::TcpAcceptor::TcpAcceptor</a></div><div class="ttdeci">TcpAcceptor(void)</div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:13</div></div>
<div class="ttc" id="tcp__connection_8h_html"><div class="ttname"><a href="tcp__connection_8h.html">tcp_connection.h</a></div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html">sock::net::TcpAcceptor</a></div><div class="ttdoc">连接接收器 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.h:24</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_affefddc37347a117e5a51dfe86cd781f"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#affefddc37347a117e5a51dfe86cd781f">sock::net::TcpAcceptor::~TcpAcceptor</a></div><div class="ttdeci">virtual ~TcpAcceptor(void)</div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:19</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_a4f61b7c7e32c3cc975f394efbfced020"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#a4f61b7c7e32c3cc975f394efbfced020">sock::net::TcpAcceptor::PassTcpConnectionPtrRefFunc</a></div><div class="ttdeci">boost::function&lt; void(TcpConnectionPtr &amp;)&gt; PassTcpConnectionPtrRefFunc</div><div class="ttdef"><b>Definition:</b> tcp_acceptor.h:28</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_a3f7e8ab49db7fa4b333430d0cf0f13ce"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#a3f7e8ab49db7fa4b333430d0cf0f13ce">sock::net::TcpAcceptor::open</a></div><div class="ttdeci">bool open(const char *addr, int port, int backlog)</div><div class="ttdoc">启动接收器 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:24</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_ad93eec19093d98d84aaa7f74486373f7"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#ad93eec19093d98d84aaa7f74486373f7">sock::net::TcpAcceptor::handleInput</a></div><div class="ttdeci">virtual void handleInput(void)</div><div class="ttdoc">处理网络输入 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:73</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_aaff5bd626bb6e5a1ce1c972fb6faf593"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#aaff5bd626bb6e5a1ce1c972fb6faf593">sock::net::TcpAcceptor::handleError</a></div><div class="ttdeci">virtual void handleError(void)</div><div class="ttdoc">处理网络错误 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:105</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_a8c313189b9166036e374750ddc64ea97"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#a8c313189b9166036e374750ddc64ea97">sock::net::TcpAcceptor::handleOutput</a></div><div class="ttdeci">virtual void handleOutput(void)</div><div class="ttdoc">处理网络输出 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:102</div></div>
<div class="ttc" id="namespacesock_html"><div class="ttname"><a href="namespacesock.html">sock</a></div><div class="ttdef"><b>Definition:</b> atomic.h:17</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_server_html"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_server.html">sock::net::TcpServer</a></div><div class="ttdef"><b>Definition:</b> tcp_server.h:29</div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_ae9d6183dfcfdc39fee3d3cd861fd7ad2"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#ae9d6183dfcfdc39fee3d3cd861fd7ad2">sock::net::TcpAcceptor::TcpConnectonGetFunc</a></div><div class="ttdeci">boost::function&lt; TcpConnectionPtr &amp;(sock_t)&gt; TcpConnectonGetFunc</div><div class="ttdef"><b>Definition:</b> tcp_acceptor.h:27</div></div>
<div class="ttc" id="net__event__handler_8h_html"><div class="ttname"><a href="net__event__handler_8h.html">net_event_handler.h</a></div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_afd658b58966444f446dd9b1cf747a04c"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#afd658b58966444f446dd9b1cf747a04c">sock::net::TcpAcceptor::handleHeartbeat</a></div><div class="ttdeci">virtual void handleHeartbeat(void)</div><div class="ttdoc">处理心跳 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:108</div></div>
<div class="ttc" id="socket_8h_html"><div class="ttname"><a href="socket_8h.html">socket.h</a></div></div>
<div class="ttc" id="classsock_1_1net_1_1_tcp_acceptor_html_aef1361f3392c7757cc0fc0a13b15163d"><div class="ttname"><a href="classsock_1_1net_1_1_tcp_acceptor.html#aef1361f3392c7757cc0fc0a13b15163d">sock::net::TcpAcceptor::handleClose</a></div><div class="ttdeci">virtual void handleClose(void)</div><div class="ttdoc">处理关闭 </div><div class="ttdef"><b>Definition:</b> tcp_acceptor.cc:111</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.10
</small></address>
</body>
</html>
